import os, sys

def label_convert():
    names = os.listdir('../icdar2015/gt')
    for i, name in enumerate(names):
        temp = name.split('_', 1)
        temp = 'res_' + temp[-1]
        with open(os.path.join('./gt', name), 'r') as f:
            lines = f.readlines()
            with open(os.path.join('./result', temp), 'w') as w:
                for line in lines:
                    line = line.rsplit(',')
                    line = line[:4]
                    line = ','.join(line)       
                    w.writelines(line+'\n')


def save_as_zipfile(txtPath='./result/', zipName='submit.zip'):
    import zipfile
    with zipfile.ZipFile(zipName, 'w') as tar:
        for txt in os.listdir(txtPath):
            tar.write(os.path.join(txtPath,txt), arcname=txt) # arcname 指定为文件名可以去除zip里的路径


def eval_func():
    save_as_zipfile()
    from script import eval
    eval(gtZip='gt.zip', submitZip='submit.zip')

if __name__ == '__main__':
    # eval_func()
    label_convert()


